package com.tyfspring.context.support;

import com.tyfspring.beans.exception.BeansException;
import com.tyfspring.beans.factory.ConfigurableListableBeanFactory;
import com.tyfspring.beans.factory.DefaultListableBeanFactory;

/**
 * @Description TODO
 * @Author shallow
 * @Date 2023/4/5 9:24
 */

public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext{

    private DefaultListableBeanFactory beanFactory;

    /**
     * 获取DefaultListableBeanFactory的实例化
     * 加载资源配置
     * @throws BeansException
     */
    @Override
    protected void refreshBeanFactory() throws BeansException {
        DefaultListableBeanFactory beanFactory = createBeanFactory();

        loadBeanDefinitions(beanFactory);
        this.beanFactory = beanFactory;
    }

    private DefaultListableBeanFactory createBeanFactory(){
        return new DefaultListableBeanFactory();
    }

    /**
     * 加载完成后完成对xml文件中的bean对象的定义和注册，同时也包括 实现了BeanFactory后处理器和bean后处理器的配置bean信息
     * @param beanFactory
     */
    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory);

    @Override
    protected ConfigurableListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
